package user;

import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-09-08
 * Time: 10:59
 */
public class Main {

    public static User login() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String name = scanner.nextLine();
        System.out.println("请输入图书馆登录密码：");
        int count = 0;
        while (count <= 3){
        String key = scanner.nextLine();
            if (key.equals("bityyds")) {
                System.out.println("登录成功，请输入你的身份：one - 管理员，else number - 普通用户");
                int choice = scanner.nextInt();
                if (choice == 1) {
                    String namekey[] = {"ljk", "msr"};
                    for (int i = 0; i < namekey.length; i++) {
                        if (name.equals(namekey[i])) {
                            return new AdminUser(name);
                        }
                    }
                    System.out.println("抱歉，您非管理员，以下为普通用户界面");
                    return new NormalUser(name);
                } else {
                    return new NormalUser(name);
                }
            }
            if (count < 3){
                System.out.println("密码错误，请重新输入: ");
            }
            count++;
        }
        System.out.println("密码错误次数过多，退出系统");
        System.exit(0);
        return null;
    }

    public static void main(String[] args) {
        BookList bookList = new BookList();
        User user = login();
        while (true){
            int choice = user.menu();
            user.doWork(choice, bookList);
        }
    }

}
